(function () {
    var $header, initMyGiteeDropdown;

    $header = $('#git-header-nav');
    $header.find('.userbar .ui.dropdown').dropdown({
        on: 'hover',
        action: 'nothing',
        onShow: function () {
            return $(this).parent().addClass('active');
        },
        onHide: function () {
            return $(this).parent().removeClass('active');
        }
    });

    initMyGiteeDropdown = function () {
        var $dimmer, $dropdown, isLoaded, isLoading, loadData, renderList;

        isLoaded = false;
        isLoading = false;
        $dropdown = $('#my-gitee-dropdown');
        $dimmer = $dropdown.find('.ui.dimmer');
        renderList = function (target, data) {
            var $target, count, html, item, name, _i, _ref, _results;

            count = data[target + '_count'];
            $target = $dropdown.find('.header.user-' + target);
            if (count < 1) {
                $target.find('a.pull-right').remove();
                return;
            }
            $target.find('.count').text('(' + count + ')');
            $target.next().remove();
            _ref = data[target + '_list'];
            _results = [];
            for (_i = _ref.length - 1; _i >= 0; _i += -1) {
                item = _ref[_i];
                name = htmlSafe(item.name);
                html = ['<a target="_blank" href="', item.url, '" title="',
                    name, '" class="item">', name, '</a>'].join('');
                _results.push($target.after(html));
            }
            return _results;
        };
        loadData = function () {
            if (isLoaded || isLoading) {
                return;
            }
            isLoading = true;
            $dimmer.addClass('active');
            $(this).parent().addClass('active');
            return $.getJSON('/api/v3/internal/my_resources', function (data) {
                $dimmer.removeClass('active');
                renderList('enterprises', data);
                renderList('projects', data);
                renderList('groups', data);
                isLoading = false;
                return isLoaded = true;
            });
        };
        $dropdown.dropdown({
            on: 'hover',
            action: 'nothing',
            onShow: loadData,
            onHide: function () {
                return $(this).parent().removeClass('active');
            }
        });
        return loadData();
    };

    initMyGiteeDropdown();

    $header.find('.ui.enterprises.dropdown').dropdown({
        on: 'hover',
        action: 'nothing'
    });

}).call(this);


(function () {
    var updateNavbar;

    updateNavbar = function () {
        if (window.scrollY > 5) {
            return $('#git-header-nav').addClass('floating');
        } else {
            return $('#git-header-nav').removeClass('floating');
        }
    };

    updateNavbar();

    $(window).on('scroll', updateNavbar);

}).call(this);


var emailStatus, commentStatus, gotopStatus;

var c_start;
c_start = document.cookie.indexOf("remote_way=");
if (c_start == -1) {
    setCookie('remote_way', "http", 360);
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name
        + "="
        + escape(value)
        + ((expiredays == null) ? "" : ";expires = "
            + exdate.toGMTString()) + ("; path = /");
}


(function () {
    $(function () {
        var $error_box, alertTip, notify_content, notify_options, setCookie, template;

        template = '<div data-notify="container" class="ui {0} message" role="alert">'
            + '<i data-notify="dismiss" class="close icon"></i>'
            + '<span data-notify="message">{2}</span>' + '</div>';
        notify_content = null;
        notify_options = {};
        alertTip = '';
        $error_box = $(".flash_error.flash_error_box");
        if (notify_options.type === 'error' && $error_box.length > 0
            && !$.isEmptyObject(notify_content.message)) {
            if (notify_content.message === 'captcha_fail') {
                alertTip = "验证码不正确";
            } else if (notify_content.message === 'not_found_in_database') {
                alertTip = "帐号或者密码错误";
            } else if (notify_content.message === 'not_found_and_show_captcha') {
                alertTip = "帐号或者密码错误";
            } else {
                alertTip = notify_content.message;
            }
            $error_box.html(alertTip).show();
        } else if (notify_content) {
            notify_options.delay = 3000;
            notify_options.template = template;
            notify_options.offset = {
                x: 10,
                y: 30
            };
            notify_options.element = '#messages-container';
            $.notify(notify_content, notify_options);
        }
        setCookie = function (name, value) {
            $.cookie(name, value, {
                path: '/',
                expires: 365
            });
        };
        return $('#remove-bulletin').on('click', function () {
            setCookie('remove_bulletin', "gitee-maintain-1516115940");
            $('#git-bulletin').hide();
        });
    });

}).call(this);


function force_mobile() {
    current_url = window.location.href;
    force_mobile_url = current_url.substr(0, current_url.indexOf('?'))
        + '?force_mobile=true';
    location.href = force_mobile_url;
}

(function () {
    // 更新底栏的位置，当页面内容高度小于窗口高度时，会将底栏浮动定位在窗口底端
    function updateFooterPosition() {
        var pageHeight = document.body.offsetHeight;
        if ($footer.hasClass('fixed-bottom')) {
            pageHeight += $footer.outerHeight();
            if (pageHeight > $(window).height()) {
                $footer.removeClass('fixed-bottom');
            }
        } else {
            if (pageHeight < $(window).height()) {
                $footer.addClass('fixed-bottom');
            }
        }
    }

    var $footer = $('#git-footer-main');
    $(document).on('ready', updateFooterPosition);
    $(window).on({
        'scroll': updateFooterPosition,
        'resize': updateFooterPosition
    });
    // 每隔一段时间检测页面高度变化，确保底栏能在页面最底端
    setInterval(updateFooterPosition, 500);
    var email = $('#git-footer-email').text();
    $('#git-footer-email').text(email.replace('#', '@'));
})();
$('.icon-popup').popup({
    position: 'bottom center'
});


(function () {
    var $gotop, $root, $toolbar, update;

    $root = $('body, html');

    $toolbar = $('.side-toolbar');

    $gotop = $('#gotop').popup({
        position: 'left center'
    }).on('click', function () {
        return $root.animate({
            scrollTop: 0
        }, 500);
    });

    update = function () {
        if ($(window).scrollTop() > 50) {
            return $gotop.addClass('active');
        } else {
            return $gotop.removeClass('active');
        }
    };

    $(window).on('scroll', update);

    update();

    $toolbar.find('.share-link').popup({
        inline: true,
        hoverable: true,
        position: 'left center',
        delay: {
            hide: 500
        }
    });

}).call(this);


var leftPeople = $('.float-left-box')
if ($.cookie('visit-gitee-stars-wus') == 1) {
    leftPeople.hide()
} else {
    leftPeople.show()
}
$('.close-left').on('click', function (e) {
    e.preventDefault()
    $.cookie('visit-gitee-stars-wus', 1, {
        path: '/',
        expires: 30
    })
    leftPeople.hide()
})